import java.math.BigDecimal;

/**
 * DebitCards are unusual because they have a CheckingAccount
 * member they need to check against whenever they make a 
 * transaction. Kind of a toss-up if they should extend Account
 * 
 * @author svene_000
 *
 */
public class DebitCard
{
	public static int lastDebitCardNumber = 0;
	public int debitCardNumber;
	public Customer cardHolder;
	public CheckingAccount checkingAccountConnectedTo;
	
	public DebitCard(Customer cardHolder, CheckingAccount cardAccount)
	{
		this.cardHolder = cardHolder;
		checkingAccountConnectedTo = cardAccount;
		debitCardNumber = lastDebitCardNumber;
		lastDebitCardNumber++;
	}
	
	/**
	 * Check that subtracting amount from balance won't be <= 0.
	 * 
	 * @param amount
	 * @return
	 */
	public boolean useDebit(BigDecimal amount)
	{
		if(checkingAccountConnectedTo.getBalance().subtract(amount).compareTo(new BigDecimal(0)) != -1)
		{
			checkingAccountConnectedTo.withdrawal(amount);
			return true;
		}
		else
		{
			return false;
		}
	}

}
